/*
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Original Code is the FxStruts MailReader Application.
 *
 * The Initial Developer of the Original Code is
 * Anirudh Sasikumar (http://anirudhs.chaosnet.org/).
 * Portions created by the Initial Developer are Copyright (C) 2008
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s):
 *
*/

package com.adobe.mailreader.model
{
    import com.adobe.cairngorm.CairngormError;
    import com.adobe.cairngorm.CairngormMessageCodes;
    import com.adobe.cairngorm.model.IModelLocator;
    import com.adobe.mailreader.events.NotifyViewEvent;
    import com.adobe.mailreader.vo.ResourceVO;

    import flash.events.EventDispatcher;
    
    import mx.collections.ArrayCollection;	
    
    /* Main model */
    [Bindable]    
    public class MailModelLocator extends EventDispatcher implements IModelLocator
    {
        private static var instance : MailModelLocator;

        /* Mediator notification event constants */
        
        public static const VIEW_LOGGED_OUT_STATE:String = 'viewLoggedOut'; 
        public static const VIEW_LOGGED_IN_STATE:String = 'viewloggedIn';
        public static const VIEW_LOGIN_FAILED:String = 'viewAuthFail';

        public static const VIEW_REGISTER_CANCEL:String = 'viewRegisterCancel';
        public static const VIEW_REGISTER_SUCCESS:String = 'viewRegisterSuccess';

        public static const VIEW_ACCOUNT_EDIT_NONE_CHOSEN:String = 'viewAccountEditNoneChosen';
        
        public static const VIEW_ACCOUNT_EDIT_FAILED:String = 'viewAccountEditFail';
        public static const VIEW_ACCOUNT_EDIT_SUCCESS:String = 'viewAccountEditSuccess';
        
        public static const VIEW_SUBSCRIPTION_EDIT_FAILED:String = 'viewSubscriptionEditFail';
        public static const VIEW_SUBSCRIPTION_EDIT_SUCCESS:String = 'viewSubscriptionEditSuccess';
        
        public static const VIEW_SUBSCRIPTION_CREATE_FAILED:String = 'viewSubscriptionCreateFail';
        public static const VIEW_SUBSCRIPTION_CREATE_SUCCESS:String = 'viewSubscriptionCreateSuccess';
        
        public static const VIEW_ACCOUNT_DELETE_NONE_CHOSEN:String = 'viewAccountDeleteNoneChosen';
        public static const VIEW_SUBSCRIPTION_DELETE_FAILED:String = 'viewSubscriptionDeleteFail';
        public static const VIEW_SUBSCRIPTION_DELETE_SUCCESS:String = 'viewSubscriptionDeleteSuccess';
        
        public static const MODEL_RESOURCES_GET_SUCCESS:String = 'resourcesGetSuccess';
        public static const MODEL_RESOURCES_GET_FAILED:String = 'resourcesGetFailed';

        public static const MODEL_LOCALE_GET_SUCCESS:String = 'localeGetSuccess';
        public static const MODEL_LOCALE_GET_FAILED:String = 'localeGetFailed';
        
        public static const MODEL_GOT_TOKEN:String = 'modelGotToken';

        /* DEPRECATED */
        public var workflowState:String = '';
        
        /* mail account data */
        public var mailSubscriptions:ArrayCollection;
        public var fromAddress:String;
        public var fullName:String;
        public var replyToAddress:String;
        public var userName:String;
        
        /* transaction token used by struts to preserve order in which
         * server side pages are hit */
        public var transactionToken:String;
        
        /* strings returned by fx:message used as text displayed by
         * the ui controls */
        public var logonTitle:String;
        public var promptUsername:String;
        public var promptPassword:String;
        public var registrationTitleCreate:String;
        public var registrationTitleEdit:String;
        public var promptPassword2:String;
        public var promptFullName:String;
        public var promptFromAddress:String;
        public var promptReplyToAddress:String;
        public var buttonSave:String;
        public var buttonCancel:String;
        public var buttonConfirm:String;
        public var headingSubscriptions:String;
        public var headingHost:String;
        public var headingUser:String;
        public var headingType:String;
        public var headingAutoconnect:String;
        public var headingAction:String;
        public var registrationDeleteSubscription:String;
        public var registrationEditSubscription:String;
        public var registrationAddSubscription:String;
        public var subscriptionTitleCreate:String;
        public var subscriptionTitleEdit:String;
        public var subscriptionTitleDelete:String;
        public var promptMailHostname:String;
        public var promptMailUsername:String;
        public var promptMailPassword:String;
        public var promptMailServerType:String;
        public var promptAutoConnect:String;
        public var promptLogon:String;
        public var promptTitle:String;
        public var promptRegister:String;
        public var promptLogoff:String;

        
        public function MailModelLocator()
        {
            if ( instance != null )
            {
                throw new CairngormError(
                    CairngormMessageCodes.SINGLETON_EXCEPTION, "AgentModelLocator" );
            }
            
            instance = this;	
        }
        
        public static function getInstance() : MailModelLocator 
        {
            if ( instance == null )
                instance = new MailModelLocator();
            
            return instance;
        }
        
        /* Our hacky view notification mechanism. Mediator concept
         * borrowed from PureMVC */
        public function notifyView(event:String, data:*=null):void
        {
            var evt:NotifyViewEvent = new NotifyViewEvent(event, false, false, data);
            dispatchEvent(evt);
        }

        /* Our hacky view notification mechanism. Mediator concept
         * borrowed from PureMVC */
        public function notifyListen(event:String, listener:Function):void
        {
            this.addEventListener(event, listener);	
        }
        
    }
}